{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<torch._C.Generator at 0x7fca44a0ae70>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "import torch.nn as nn\n",
    "from torch.autograd import Variable\n",
    "torch.manual_seed(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "------------input------------\n",
      "Variable containing:\n",
      "(0 ,.,.) = \n",
      " -0.4461 -1.7313  0.3699 -0.3564\n",
      " -0.3377 -0.1462  0.2211  0.2101\n",
      " -0.6409 -0.0282 -0.5603 -0.0125\n",
      "  0.4262 -1.0960  0.8607 -1.9942\n",
      " -1.3192 -0.4212  1.4077 -0.3445\n",
      "\n",
      "(1 ,.,.) = \n",
      " -0.1371 -0.4603 -0.7347 -0.1396\n",
      "  0.2408 -0.5533 -2.0483  1.1918\n",
      "  0.8283  0.1775 -2.0114 -0.8362\n",
      "  0.6369  1.0047 -0.0170 -1.8938\n",
      "  0.6460 -0.5101  0.9348 -0.7416\n",
      "[torch.FloatTensor of size 2x5x4]\n",
      "\n",
      "-------------h0--------------\n",
      "Variable containing:\n",
      "(0 ,.,.) = \n",
      " -0.5200 -2.6718  1.1100 -1.4660  1.2769 -0.5401  1.8059 -0.5611\n",
      "  1.1396 -0.2842 -1.3839 -2.2763  0.6903 -0.7146 -0.6641  0.1318\n",
      "[torch.FloatTensor of size 1x2x8]\n",
      "\n",
      "-----------output------------\n",
      "Variable containing:\n",
      "(0 ,.,.) = \n",
      " -0.8269  0.5821 -0.3771 -0.6001 -0.2826  0.4665 -0.7994  0.6679\n",
      " -0.1299  0.5016 -0.5509 -0.1767 -0.3701  0.4761  0.5418 -0.3435\n",
      " -0.3707  0.2710 -0.0693 -0.2781  0.1795  0.3329 -0.3951 -0.3599\n",
      " -0.7371  0.7549 -0.7227 -0.7748  0.0031 -0.5893 -0.1918  0.0820\n",
      " -0.3120  0.0304 -0.5284 -0.7872 -0.5912  0.6447  0.6986  0.2810\n",
      "\n",
      "(1 ,.,.) = \n",
      "  0.7591  0.7558 -0.0110 -0.7744  0.0326  0.5142  0.4415  0.8459\n",
      "  0.0767  0.1927  0.5806  0.5193  0.7514  0.3892 -0.4128 -0.6041\n",
      " -0.4266  0.8647 -0.1858  0.0777  0.7475 -0.4314 -0.6181  0.0252\n",
      " -0.2266  0.8464 -0.8077 -0.5185  0.6583 -0.1323  0.6981  0.4534\n",
      " -0.5025  0.0468 -0.6007 -0.5744  0.4496  0.2915  0.5066 -0.2065\n",
      "[torch.FloatTensor of size 2x5x8]\n",
      "\n",
      "-------------hn--------------\n",
      "Variable containing:\n",
      "(0 ,.,.) = \n",
      " -0.3120  0.0304 -0.5284 -0.7872 -0.5912  0.6447  0.6986  0.2810\n",
      " -0.5025  0.0468 -0.6007 -0.5744  0.4496  0.2915  0.5066 -0.2065\n",
      "[torch.FloatTensor of size 1x2x8]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "rnn = nn.RNN(4, 8, 1, batch_first=True)\n",
    "input = Variable(torch.randn(2, 5, 4))\n",
    "h0 = Variable(torch.randn(1, 2, 8))\n",
    "output, hn = rnn(input, h0)\n",
    "print(\"------------input------------\")\n",
    "print(input)\n",
    "print(\"-------------h0--------------\")\n",
    "print(h0)\n",
    "print(\"-----------output------------\")\n",
    "print(output)\n",
    "print(\"-------------hn--------------\")\n",
    "print(hn)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import MetaRNNs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "------------test_input------------\n",
      "Variable containing:\n",
      "(0 ,.,.) = \n",
      "  0.5647 -0.0149  0.0574  0.5602\n",
      "  0.4298  0.0119  1.1331 -1.9944\n",
      "  0.4831 -1.0969  0.1022 -1.4136\n",
      "  0.0774  0.5084 -0.5412 -0.7290\n",
      "  0.2095  0.0149  0.3100  0.4768\n",
      "\n",
      "(1 ,.,.) = \n",
      "  1.0342  0.1276 -1.4104 -0.5135\n",
      " -0.9745 -0.4833  0.7045  0.0290\n",
      " -0.4813  0.6683  1.0597  0.2267\n",
      " -1.1349 -0.6896  0.3592 -0.1910\n",
      " -0.7895 -0.0094  0.2919 -1.0424\n",
      "[torch.FloatTensor of size 2x5x4]\n",
      "\n",
      "------------test_output------------\n",
      "Variable containing:\n",
      "(0 ,.,.) = \n",
      "  0.0306  0.0000  0.0000  0.0235  0.0000  0.0000  0.0997  0.0000\n",
      "  0.0212  0.0000  0.0091  0.0000  0.0000  0.0000  0.0495  0.0016\n",
      "  0.0177  0.0000  0.0011  0.0000  0.0000  0.0000  0.0403  0.0000\n",
      "  0.0433  0.0000  0.0000  0.0726  0.0000  0.0088  0.1188  0.0000\n",
      "  0.0524  0.0000  0.0251  0.0000  0.0000  0.0033  0.1316  0.0351\n",
      "\n",
      "(1 ,.,.) = \n",
      "  0.0134  0.0000  0.0000  0.0085  0.0000  0.0000  0.0377  0.0000\n",
      "  0.0400  0.0188  0.0000  0.0000  0.0154  0.0000  0.0000  0.0000\n",
      "  0.1052  0.0390  0.0000  0.0000  0.0214  0.0000  0.0000  0.0000\n",
      "  0.1346  0.0392  0.0000  0.0000  0.0453  0.0000  0.0000  0.0147\n",
      "  0.0488  0.0127  0.0000  0.0000  0.0000  0.0070  0.0000  0.0003\n",
      "[torch.FloatTensor of size 2x5x8]\n",
      "\n",
      "--------------test_hn--------------\n",
      "Variable containing:\n",
      "(0 ,.,.) = \n",
      "  0.0524  0.0000  0.0251  0.0000  0.0000  0.0033  0.1316  0.0351\n",
      "  0.0488  0.0127  0.0000  0.0000  0.0000  0.0070  0.0000  0.0003\n",
      "[torch.FloatTensor of size 1x2x8]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "test_rnn = MetaRNNs.MetaRNN(4, 8, 4, 4, 1)\n",
    "test_input = Variable(torch.randn(2, 5, 4))\n",
    "# test_h0 = Variable(torch.randn(1, 8))\n",
    "test_output, test_hn = test_rnn(input)\n",
    "print(\"------------test_input------------\")\n",
    "print(test_input)\n",
    "print(\"------------test_output------------\")\n",
    "print(test_output)\n",
    "print(\"--------------test_hn--------------\")\n",
    "print(test_hn)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "------------input------------\n",
      "Variable containing:\n",
      "(0 ,.,.) = \n",
      " -2.2331  0.5397 -0.6181 -0.0376\n",
      " -0.6415 -1.8803  1.3234 -1.0395\n",
      "  1.5467  0.0520  0.4520  0.5046\n",
      "  1.2080 -0.1941  0.5541  0.8150\n",
      "  1.6145 -1.2233 -0.3918 -1.3062\n",
      "[torch.FloatTensor of size 1x5x4]\n",
      "\n",
      "-------------h0--------------\n",
      "Variable containing:\n",
      "(0 ,.,.) = \n",
      "  0.5925 -0.3967  0.2228  0.4171 -0.2966  0.7743 -0.4692 -0.9039\n",
      "[torch.FloatTensor of size 1x1x8]\n",
      "\n",
      "-------------c0--------------\n",
      "Variable containing:\n",
      "(0 ,.,.) = \n",
      " -0.4642 -0.8735  1.1043  0.0693 -0.4859 -0.3159  0.5944 -0.7041\n",
      "[torch.FloatTensor of size 1x1x8]\n",
      "\n",
      "-----------output------------\n",
      "Variable containing:\n",
      "(0 ,.,.) = \n",
      " -0.0969 -0.0559  0.2303 -0.1929 -0.1332 -0.0373  0.1813 -0.1977\n",
      " -0.0285 -0.0695  0.1505 -0.0408  0.2293 -0.2797 -0.0548 -0.0344\n",
      "  0.1695 -0.2984  0.3312  0.0600  0.2093 -0.1719 -0.0209  0.0549\n",
      "  0.2105 -0.3698  0.3761  0.0667  0.2166 -0.1620 -0.0288  0.0959\n",
      "  0.3009 -0.3119  0.4015  0.0591  0.2463 -0.3964 -0.0223  0.1532\n",
      "[torch.FloatTensor of size 1x5x8]\n",
      "\n",
      "-------------hn--------------\n",
      "(Variable containing:\n",
      "(0 ,.,.) = \n",
      "  0.3009 -0.3119  0.4015  0.0591  0.2463 -0.3964 -0.0223  0.1532\n",
      "[torch.FloatTensor of size 1x1x8]\n",
      ", Variable containing:\n",
      "(0 ,.,.) = \n",
      "  0.6199 -0.7743  0.8528  0.1128  0.6951 -0.8730 -0.0461  0.3544\n",
      "[torch.FloatTensor of size 1x1x8]\n",
      ")\n"
     ]
    }
   ],
   "source": [
    "lstm = nn.LSTM(4, 8, 1, batch_first=True)\n",
    "input = Variable(torch.randn(1, 5, 4))\n",
    "h0 = Variable(torch.randn(1, 1, 8))\n",
    "c0 = Variable(torch.randn(1, 1, 8))\n",
    "output, hn = lstm(input, (h0, c0))\n",
    "print(\"------------input------------\")\n",
    "print(input)\n",
    "print(\"-------------h0--------------\")\n",
    "print(h0)\n",
    "print(\"-------------c0--------------\")\n",
    "print(c0)\n",
    "print(\"-----------output------------\")\n",
    "print(output)\n",
    "print(\"-------------hn--------------\")\n",
    "print(hn)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "------------test_input------------\n",
      "Variable containing:\n",
      "(0 ,.,.) = \n",
      "  0.0373  0.3506 -0.4350  0.4519\n",
      " -1.7134 -0.1292 -0.3674 -1.3110\n",
      " -1.8411 -1.0795 -1.3460 -0.0047\n",
      " -0.2794 -0.0668 -0.8571  1.2471\n",
      " -0.7591  1.1883  0.8367  1.1460\n",
      "[torch.FloatTensor of size 1x5x4]\n",
      "\n",
      "------------test_output------------\n",
      "Variable containing:\n",
      "(0 ,.,.) = \n",
      "1.00000e-02 *\n",
      "   0.2425  0.0940 -0.3432 -0.0524 -0.2168  0.0403 -0.2298 -0.1012\n",
      "   0.1670 -0.2396 -0.4936  0.2343 -0.0869 -0.1142 -0.4152 -0.0269\n",
      "   0.0004 -0.5250 -0.7615  0.3773  0.0598 -0.1963 -0.7230 -0.1185\n",
      "   0.3392 -0.3949 -1.0631  0.2675 -0.2053  0.0314 -0.8860 -0.2581\n",
      "   0.5161 -0.0836 -1.0890  0.0021 -1.0511 -0.0010 -0.8436 -0.3369\n",
      "[torch.FloatTensor of size 1x5x8]\n",
      "\n",
      "--------------test_hn------------\n",
      "(Variable containing:\n",
      "(0 ,.,.) = \n",
      "1.00000e-02 *\n",
      "   0.5161 -0.0836 -1.0890  0.0021 -1.0511 -0.0010 -0.8436 -0.3369\n",
      "[torch.FloatTensor of size 1x1x8]\n",
      ", Variable containing:\n",
      "(0 ,.,.) = \n",
      "1.00000e-02 *\n",
      "   1.0204 -0.1676 -2.1862  0.0042 -2.0933 -0.0020 -1.6723 -0.6775\n",
      "[torch.FloatTensor of size 1x1x8]\n",
      ")\n"
     ]
    }
   ],
   "source": [
    "test_lstm = MetaRNNs.MetaLSTM(4, 8, 4, 4, 1)\n",
    "test_input = Variable(torch.randn(1, 5, 4))\n",
    "# test_h0 = Variable(torch.randn(1, 8))\n",
    "test_output, test_hn = test_lstm(test_input)\n",
    "print(\"------------test_input------------\")\n",
    "print(test_input)\n",
    "print(\"------------test_output------------\")\n",
    "print(test_output)\n",
    "print(\"--------------test_hn------------\")\n",
    "print(test_hn)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
